import 'package:flutter/material.dart';
import 'package:tiktokadult/assets_tool/images.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';

class CErrorWidget extends StatefulWidget {
  final String? errorMsg;
  final String? errorMsg2;
  final VoidCallback? retryOnTap;

  const CErrorWidget({
    super.key,
    this.errorMsg = "数据被掏空，请稍后重试",
    this.errorMsg2,
    this.retryOnTap,
  });

  @override
  State<StatefulWidget> createState() {
    return CErrorWidgetState();
  }
}

class CErrorWidgetState extends State<CErrorWidget> {
  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(builder: (_, cons) {
      if (cons.maxHeight < 146) return SizedBox.shrink();
      return Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Image.asset("ic_nodata.webp".commonImgPath, height: 150),
              11.sizeBoxH,
              Text(
                widget.errorMsg ?? "",
                style: TextStyle(color: Color(0xff999999), fontSize: 14),
              ),
              Visibility(
                visible: widget.retryOnTap != null,
                child: InkWell(
                  onTap: widget.retryOnTap,
                  child: Container(
                    padding: const EdgeInsets.fromLTRB(12, 8, 12, 12),
                    child: Text(
                      "点击重试",
                      style: TextStyle(
                        color: Color(0xff3E64EA).withOpacity(0.7),
                        fontSize: 12,
                      ),
                    ),
                  ),
                ),
              )
            ],
          )
        ],
      );
    });
  }
}
